package com.aaa.ps.controller;

import com.aaa.common.entity.Role;
import com.aaa.common.util.Constants;
import com.aaa.common.util.Result;
import com.aaa.ps.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * fileName:RoleController
 * description:
 * author:zz
 * createTime:2020/8/28 16:33
 * version:1.0.0
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 根据ID删除
     * @param roleId
     * @return
     */
    @DeleteMapping("deleteByPrimaryKey")
    public Result deleteByPrimaryKey(Integer roleId) {
        int i = roleService.deleteByPrimaryKey(roleId);
        if(i>0){
            return new Result<>(Constants.RESULT.SUCCESS,Constants.RESULT.SUCMESSAGE);
        }
        return new Result<>(Constants.RESULT.INNERERROR,Constants.RESULT.IEMESSAGE);
    }

    /**
     * 添加
     * @param record
     * @return
     */
    @PostMapping("insertSelective")
    public int insertSelective(@RequestBody Role record) {
        return roleService.insertSelective(record);
    }

    /**
     * 根据ID查询
     * @param roleId
     * @return
     */
    @GetMapping("selectByPrimaryKey")
    public Role selectByPrimaryKey(Integer roleId) {
        return roleService.selectByPrimaryKey(roleId);
    }

    /**
     * 更新
     * @param record
     * @return
     */
    @PutMapping("updateByPrimaryKeySelective")
    public int updateByPrimaryKeySelective(Role record) {
        return roleService.updateByPrimaryKeySelective(record);
    }


    /**
     * 批量添加角色权限关联
     * @param roleId
     * @param menuIds
     * @return
     */
    @PutMapping("insertRoleMenu")
    public Result insertRoleMenu(Integer roleId,String menuIds){
        roleService.batchInsertRoleMenu(roleId,menuIds);
        return new Result<>(Constants.RESULT.SUCCESS,Constants.RESULT.SUCMESSAGE);
    }
}
